﻿using Microsoft.EntityFrameworkCore;
using Production.DomainLib.AggregatesModel.StandardBomAggregate;
using Swimj.DomainLib.SeedWork;

namespace Production.InfrastructureLib.Repositories
{
    public class StandardBomRepository : IStandardBomRepository
    {
        private readonly ProductionDbContext _dbContext;
        public IUnitOfWork UnitOfWork => _dbContext;

        public StandardBomRepository(ProductionDbContext dbContext)
        {
            _dbContext = dbContext;
        }

        public StandardBom Add(StandardBom standardBom)
        {
            return _dbContext.StandardBoms.Add(standardBom).Entity;
        }

        public Task<StandardBom?> Get(int requestId)
        {
            return _dbContext.StandardBoms.Include(i => i.Items)
                .FirstOrDefaultAsync(i => i.Id == requestId);
        }
    }
}